import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { NaiveUiResolver } from "unplugin-vue-components/resolvers";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports: [
        "vue",
        {
          "naive-ui": [
            "useDialog",
            "useMessage",
            "useNotification",
            "useLoadingBar",
          ],
        },
      ],
    }),
    Components({
      resolvers: [NaiveUiResolver()],
    }),
  ],
  resolve: {
    // 路径别名配置
    alias: {
      // @ 别名，指向 src 目录
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  build: {
    rollupOptions: {
      output: {
        manualChunks: {
          system: [
            "./src/views/system/user/index.vue",
            "./src/views/system/menu/index.vue",
            "./src/views/system/role/index.vue",
          ],
          banner: [
            "./src/views/banner/add/index.vue",
            "./src/views/banner/add-new/index.vue",
            "./src/views/banner/list/index.vue",
            "./src/views/banner/list-new/index.vue",
          ],
          product: [
            "./src/views/product/list/index.vue",
            "./src/views/product/list-new/index.vue",
            "./src/views/product/search-list/index.vue",
          ],
        },
      },
    },
  },
});
